<?php
class ChudautsController extends AppController {

	var $name = 'Chudauts';
	var $uses= array('Ctrinh','Chudaut', 'Tinh');
	function index() {
		$this->Chudaut->recursive = -1;
		$this->set('chudauts', $this->paginate('Chudaut'));
		
		
	}
	function chuct($idchu) {
		$this->Chudaut->recursive = -1;
		$tc=$this->Chudaut->find('first', array('id' => $idchu));
		$this->Ctrinh->recursive = 0;
		$this->set('ctrinhs', $this->paginate('Ctrinh', array('chudaut_id' =>$idchu)));
		$this->set(compact('tc'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid chudaut', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('chudaut', $this->Chudaut->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Chudaut->create();
			if ($this->Chudaut->save($this->data)) {
				$this->Session->setFlash(__('The chudaut has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid chudaut', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Chudaut->save($this->data)) {
				$this->Session->setFlash(__('The chudaut has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Chudaut->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for chudaut', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Chudaut->delete($id)) {
			$this->Session->setFlash(__('Chudaut deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Chudaut was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
